<?php
ob_start();
session_start();

	if(!isset($_SESSION["admin_key"])) {
		header("location:index.php");
	}

include("../conf/config.php");
include("../conf/database.php");
include("../conf/tools.php");

if(!checkRole(SUPER_ADMIN))  header("location:registrants.php");

//note: if word file for dump desired, link to this page like:
//<a href='dump.php?w=1'>link</a>
//if this parameter is not included, file returned will be in excel format

$mode=$_GET["mode"];
$list_id=$_GET["list_id"];



$listInfo=@array_pop(qry_data("select list_title from bkitc_invite_list where list_id=".$list_id));

if($mode==1) $title="Members Linked to this List - ".$listInfo["list_title"];
if($mode==2) $title="Members Invited List - ".$listInfo["list_title"];
if($mode==3) $title="Members Accepted List - ".$listInfo["list_title"];
//if($mode==4) $title="Members Pending List - ".$listInfo["list_title"];
if($mode==5) $title="Members Cancelled List - ".$listInfo["list_title"];

$fileexportName=$title;

$file_type = "vnd.ms-excel";
$file_ending = "xls";

header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=$fileexportName.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
//get contents
//define date for title
$now_date = date('d-m-Y H:i');
$title = "Member Registrations as of $now_date";



$memberInfoColNames=Array(
"P.registrant_id"=>"Registrant ID",
"P.full_name"=>"Full Name",
"P.gender"=>"Gender",
"P.dob"=>"Date Of Birth",
"P.contact_address"=>"Contact Address",
"P.reg_city"=>"City",
"P.reg_state"=>"State",
"P.reg_country"=>"Country",
"P.telephone_no"=>"Telephone No",
"P.mobile_no"=>"Mobile No",
"P.email_id"=>"Email Id",
"P.bk_center_address"=>"BK Center Address",
"P.bk_center_phone"=>"BK Center Phone",
"P.bk_center_email"=>"BK Center Email",
"LM.rec_created"=>"Invited Date",
"L.list_title"=>"Invited For",
"LM.inv_status"=>"Invited or Not"
);



$keyNames=implode(",",array_keys($memberInfoColNames));

if($mode==1){

$sql="select ".$keyNames." from bkitc_profiles P
 JOIN bkitc_invite_list_mem LM on P.registrant_id=LM.mem_id JOIN 
 bkitc_invite_list L ON L.list_id=LM.list_id 
 where L.list_id=".$list_id;
}

if($mode==2){

$sql="select ".$keyNames." from bkitc_profiles P
 JOIN bkitc_invite_list_mem LM on P.registrant_id=LM.mem_id JOIN 
 bkitc_invite_list L ON L.list_id=LM.list_id 
 where  LM.inv_status=1 and L.list_id=".$list_id;
}

if($mode==2){

$sql="select ".$keyNames." from bkitc_profiles P
 JOIN bkitc_invite_list_mem LM on P.registrant_id=LM.mem_id JOIN 
 bkitc_invite_list L ON L.list_id=LM.list_id 
 where  LM.inv_status=1 and L.list_id=".$list_id;
}

if($mode==3 || $mode==5){


unset($memberInfoColNames["LM.rec_created"]);
unset($memberInfoColNames["L.list_title"]);
unset($memberInfoColNames["LM.inv_status"]);

$memberInfoColNames["LM.acc_status"]="Accept/Cancel Status";
$memberInfoColNames["LM.accepted_on"]="Accepted On";
$memberInfoColNames["LM.cancelled_on"]="Cancelled On";
$memberInfoColNames["LM.invited_date"]="Invited Date";
$memberInfoColNames["LM.mem_notes"]="Member Notes";
$memberInfoColNames["LM.journey_notes"]="Journey Notes";
$memberInfoColNames["LM.journey_via"]="Coming through";
$memberInfoColNames["LM.journey_cab"]="Cab Info";
$memberInfoColNames["LM.permission_letter"]="Permission Letter";
$memberInfoColNames["LM.permission_letter_on"]="Letter subnmitted date";
$memberInfoColNames["LM.dt_arrival"]="Arrival Date";
$memberInfoColNames["LM.dt_departure"]="Departure Date";
$memberInfoColNames["LM.dep_venue"]="Depart Venue";
$memberInfoColNames["LM.dep_time"]="Depart Time";
$memberInfoColNames["LM.arr_venue"]="Arrival Venue";
$memberInfoColNames["LM.arr_time"]="Arrival Time";



$keyNames=implode(",",array_keys($memberInfoColNames));

$prgInfo=@array_pop(qry_data("select list_event_id from bkitc_invite_list where list_id=".$list_id));
$prg_id=$prgInfo["list_event_id"];


$stats=1;
if($mode==5) $stats=2;
$sql="SELECT ".$keyNames." FROM bkitc_program_members LM join  bkitc_profiles P on
 LM.member_id=P.registrant_id where LM.rec_status=1 and LM.acc_status=$stats and LM.program_id='".$prg_id."'";

}
//echo $sql;
$result = mysql_query($sql);

$i = mysql_num_fields($result);
echo "Member Events Invitations as of $now_date ";
$str = '<table border="1" style="border-collapse: collapse"><tr>';

foreach($memberInfoColNames as $colId=>$colName)
{
   $str .= '<th>'.$colName.'</th>';

}
	
 
$str .= '</tr>';

$count = mysql_num_rows($result);
$total = $count;

while ($row = mysql_fetch_array($result)) {
	$str .= '<tr>';
	if($row["are_you_bk"]=="0") $row["aloukik_dob"]="";
	if($row["gender"]=="1") $row["gender"]= "Male"; else $row["gender"]=  "Female";
	if($row["are_you_bk"]=="1") $row["are_you_bk"]=  "Yes"; else $row["are_you_bk"]=  "No";
	if($row["reg_type"]=="1") $row["reg_type"]=  "Site"; else $row["reg_type"]=  "Admin";
	$row["reg_sig"]=getMemberSIGNameList($row["registrant_id"]);
	$row["registrant_id"]= "BKITC".number_pad($row["registrant_id"],5);
	

	foreach($memberInfoColNames as $colId=>$colName)
	{
	   $colId=str_replace("P.", "", $colId);
	   $colId=str_replace("L.", "", $colId);
	   $colId=str_replace("LM.", "", $colId);


	if($colId=="prg_reg_status") $row[$colId]=$prg_status[$row[$colId]];
 		if($colId=="inv_status") $row[$colId]=$row[$colId]==1?"Yes":"No";
		if($colId=="acc_status"){

			$statusabel=$row[$colId]==1?"Accepted":"Cancelled";
			if($row[$colId]==0) $statusabel="No Response";
			$row[$colId]=$statusabel;
		} 	

	   if($colId=="are_you_prof") $row[$colId]=$row[$colId]==1?"Yes":"No";
	   if($colId=="reg_bk_stats") $row[$colId]=$class_status[$row[$colId]];
	   if($colId=="rec_status") $row[$colId]=$row[$colId]==1?"Active":"Deleted";
	   $str .= '<td>'.$row[$colId].'</td>';

	
	}
		

	$str .= '</tr>';
}

$str .= '</table>';

mysql_free_result($result);

echo $str;

?>

